package com.ysqcould.web.controller.content;


import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import com.ysqcould.content.domain.Notice;
import com.ysqcould.content.service.INoticeService;
import com.ysqcould.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 协会公告Controller
 * 
 * @author ruoyi
 * @date 2022-06-28
 */
@RestController
@RequestMapping("/content/notice")
public class NoticeController extends BaseController
{
    @Autowired
    private INoticeService tNoticeService;

    @Autowired
    private ISysUserService userService;

    /**
     * 查询协会公告列表
     */
    @PreAuthorize("@ss.hasPermi('content:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(Notice tNotice)
    {
        startPage();
        List<Notice> list = tNoticeService.selectTNoticeList(tNotice);
        return getDataTable(list);
    }

    /**
     * 导出协会公告列表
     */
    @PreAuthorize("@ss.hasPermi('content:notice:export')")
    @Log(title = "协会公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Notice tNotice)
    {
        List<Notice> list = tNoticeService.selectTNoticeList(tNotice);
        ExcelUtil<Notice> util = new ExcelUtil<Notice>(Notice.class);
        util.exportExcel(response, list, "协会公告数据");
    }

    /**
     * 获取协会公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('content:notice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tNoticeService.selectTNoticeById(id));
    }

    /**
     * 新增协会公告
     */
    @PreAuthorize("@ss.hasPermi('content:notice:add')")
    @Log(title = "协会公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Notice tNotice)
    {
        tNotice.setAsId(getUserId());
        return toAjax(tNoticeService.insertTNotice(tNotice));
    }

    /**
     * 修改协会公告
     */
    @PreAuthorize("@ss.hasPermi('content:notice:edit')")
    @Log(title = "协会公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Notice tNotice)
    {
        return toAjax(tNoticeService.updateTNotice(tNotice));
    }

    /**
     * 删除协会公告
     */
    @PreAuthorize("@ss.hasPermi('content:notice:remove')")
    @Log(title = "协会公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tNoticeService.deleteTNoticeByIds(ids));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('content:user:edit')")
    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody Notice notice)
    {
        return toAjax(tNoticeService.updateUserStatus(notice));
    }
}
